package com.mk.carcassonne.drawables;

import com.mk.carcassonne.Global;
import com.mk.carcassonne.Position;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;

public class Brick implements Drawable{
	private Position _position;
	private Integer _rotation;
	private Bitmap _brickImage;
	private BrickEdgeTypeCollection _brickEdgeTypeCollection;
	private Boolean _hasCloister;
	private Boolean _hasPennant;
	private Integer _largeBrickId;
	private FollowerPlacementCollection _followerPlacementCollection;
	
	public Brick(Bitmap brickImage, Position position, Integer rotation, BrickEdgeTypeCollection brickEdgeTypeCollection, Boolean hasCloister, Boolean hasPennant, Integer largeBrickId, FollowerPlacementCollection followerPlacementCollection) {
		_position = position;
		_rotation = rotation;
		_brickImage = brickImage;
		_brickEdgeTypeCollection = brickEdgeTypeCollection;
		_hasCloister = hasCloister;
		_hasPennant = hasPennant;
		_largeBrickId = largeBrickId;
		_followerPlacementCollection = followerPlacementCollection;
	}

	public void draw(Context context, Canvas canvas, Position shift) {
		
		Matrix m = new Matrix();
		if(_rotation != null)
		{
			m.postRotate(_rotation * Global.DEFAULT_ROTATION, Global.BRICK_SIZE / 2, Global.BRICK_SIZE / 2);			
		}
		
		int x = shift.getX();
		int y = shift.getY();
		if(_position != null)
		{
			x += _position.getX() * Global.BRICK_SIZE;
			y += _position.getY() * Global.BRICK_SIZE;
		}
		
		m.postTranslate(x, y);
		
		canvas.drawBitmap(_brickImage, m, null);
	}

	public Bitmap getBitmap() {
		return _brickImage;
	}

	public void setPosition(Position position) {
		_position = position;
	}
	
	public Position getPosition() {
		return _position;
	}

	public void rotate() {
		_rotation += 1;
		if(_rotation > 3)
		{
			_rotation = 0;
		}
	}

	public int getRotation() {
		return _rotation;
	}
	
	public BrickEdgeTypeCollection getBrickEdgeTypeCollection() {
		return _brickEdgeTypeCollection;
	}

	public Boolean hasCloister() {
		return _hasCloister;
	}

	public Integer getLargeBrickId() {
		return _largeBrickId;
	}

	public FollowerPlacementCollection getFollowerPlacementCollection() {
		return _followerPlacementCollection;
	}
}
